// ++++++++++++++++++++++++++++++++++++++++
// 《Go Web编程实战派从入门到精通》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// 仓库地址：https://gitee.com/shirdonl/goWebActualCombat
// 仓库地址：https://github.com/shirdonl/goWebActualCombat
// ++++++++++++++++++++++++++++++++++++++++
package main

import "fmt"

type Engine interface {
	Start()
	Stop()
}

type Bus struct {
	Engine // 包含 Engine 类型的匿名字段
}

// 实现 Engine 接口的具体类型
type DieselEngine struct{}

func (d *DieselEngine) Start() {
	fmt.Println("Diesel engine starting...")
}

func (d *DieselEngine) Stop() {
	fmt.Println("Diesel engine stopping...")
}

func (c *Bus) Working() {
	c.Start() // 开动汽车
	c.Stop()  // 停车
}

func main() {
	// 创建一个 DieselEngine 实例并将其赋值给 Bus 的 Engine 字段
	engine := &DieselEngine{}
	bus := &Bus{Engine: engine}

	// 使 Bus 开始工作
	bus.Working()
}

//go run 1.6-object4.go
//Diesel engine starting...
//Diesel engine stopping...
